package com.sentrix.auto.printercenter.presentation.a4;

import com.sentrix.auto.printercenter.application.A4PrintService;
import com.sentrix.auto.printercenter.presentation.common.DataResponse;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * A4打印业务
 */
@Slf4j
@RestController
@RequestMapping("a4-printer")
public class A4PrinterController {

    @Resource
    private A4PrintService a4PrintService;


    /**
     * 扫码,生成打印任务。
     * 根据订单码从上游系统获取文件地址
     *
     * @param agentMac
     * @param orderCode
     * @return
     */
    @RequestMapping("scan/{orderNo}")
    public DataResponse scan(@RequestHeader("agentMac") String agentMac, @RequestParam("orderCode") String orderCode) {
        a4PrintService.scanAndCreateTask(agentMac, orderCode);
        return new DataResponse("1", true, 200, "打印成功");
    }

    /**
     * A4机器空闲，发送打印信号
     *
     * @param agentMac
     * @return
     */
    @RequestMapping("print")
    public DataResponse print(@RequestHeader("agentMac") String agentMac) {
        return new DataResponse("1", true, 200, "打印成功");
    }

    /**
     * 重置A4设备相关的打印任务
     * 当A4设备出现异常时，整个设备的任务全部重置，然后重新开始打印任务
     *
     * @param agentMac
     * @return
     */
    @RequestMapping("reset")
    public DataResponse reset(@RequestHeader("agentMac") String agentMac) {
        return new DataResponse("1", true, 200, "打印成功");
    }
}
